﻿using System;

using System.Collections.Generic;
using System.Text;

namespace NetToolsV2
{
    class RttStats
    {
        private uint m_minRTT;
        public uint MinRTT { get { return m_minRTT; } }

        private uint m_maxRTT;
        public uint MaxRTT { get { return m_maxRTT; } }

        private double m_averageRTT;
        public double AverageRTT { get { return m_averageRTT; } }

        private int m_paketCount;
        public int PaketCount { get { return m_paketCount; } }

        DateTime m_startOfCollection;

        public DateTime StartOfCollection
        {
            get { return m_startOfCollection; }
        }

        private bool m_updated;
        public RttStats()
        {
            Clear();
        }

        public void Clear()
        {
            m_minRTT = 0;
            m_maxRTT = 0;
            m_averageRTT = 0.0;
            m_paketCount = 0;
            m_updated = false;
        }

        public void UpdateStats(uint rtt)
        {
            m_paketCount++;
            if (m_updated)
            {
                if (rtt < m_minRTT)
                    m_minRTT = rtt;
                if (rtt > m_maxRTT)
                    m_maxRTT = rtt;
                m_averageRTT = (m_averageRTT + rtt) / 2;
            }
            else
            {
                m_updated = true;
                m_startOfCollection = DateTime.Now;
                m_minRTT = rtt;
                m_maxRTT = rtt;
                m_averageRTT = rtt;
            }
        }
    }
}
